package com.jinsi.controller.yrf;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.constant.YrfConstant;
import com.jinsi.pojo.CustomerServiceManagement;
import com.jinsi.service.yrf.CustomerServiceManagementService;
import com.jinsi.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @author: 86185
 * @description: 客服管理
 * @date 2022/9/13
 */
@RestController
@RequestMapping("/customerServiceManagement")
@Slf4j
public class CustomerServiceManagementController {
    @Autowired
    private CustomerServiceManagementService customerServiceManagementService;

    /**
     * 分页获取数据（模糊查询）
     * @param page 分页
     * @param limit 分页
     * @return 前端需要的数据
     */
    @RequestMapping("/getAll")
    public R getAll(Integer page, Integer limit){
        PageHelper.startPage(page,limit);
        List<CustomerServiceManagement> all = customerServiceManagementService.getAll();
        PageInfo<CustomerServiceManagement> pageInfo = new PageInfo<>(all);

        return R.custom(YrfConstant.LAYUI_CODE,
                YrfConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());

    }

    /**
     * 删除客服管理列表
     * @param cusSerId 根据cusSerId删除
     * @return 状态码
     */
    @RequestMapping("/del")
    public R cusdelete(int cusSerId){
        R re = null;
        try {
            customerServiceManagementService.cusdelete(cusSerId);
            re = R.ok("成功");
        } catch (Exception e) {
            e.printStackTrace();
            re = R.error("失败");
            log.error("删除客服管理error为: --->",e);
        }
        return re;
    }
}
